#Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16
#Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5
from urllib  import request #从摸个模块中引入对象
from urllib.request import urlopen
import time,os
from bs4 import BeautifulSoup
headers = {'User-Agent':'iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5'}
for i in range(6000,6015):
    url = f'https://e6e28f7353c0746f565.bi28.cc/html/45333/{i}.html'
    req = request.Request(url=url,headers=headers)
    res = request.urlopen(req)#将包装好的请求头 发送
    html = res.read().decode('utf-8')
    print(html)
    soup = BeautifulSoup(html,'html')
    title = soup.find('div', class_='header').find('span',class_='title').text.replace(' ', '_').replace('	','_').replace(' ', '\t').replace( '1）',' ').replace('修罗武神','')
    title = title[:len(title)-1:]
    #begin_index = title.find('\n')
    #end_index = title.find('	')
    content = soup.find('div',id='chaptercontent').text.replace(' ','\n') .replace('<br />','\n')
    # print(title)
    # print(content)

    if not os.path.exists(r"d:\\小说\\修罗武神"):
       os.makedirs(r"d:\\小说\\修罗武神")
    f = open(r"d:\\小说\\修罗武神\\"+ title + ".txt",'a+',encoding='utf-8')
    f.write(title+'\n')
    f.write(content+'\n')
    f.close()
    time.sleep(1)